package com.splic.product.service.impl;

import java.util.Date;
import java.util.List;
import com.splic.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.splic.product.mapper.UserCollectionRecordMapper;
import com.splic.product.domain.UserCollectionRecord;
import com.splic.product.service.UserCollectionRecordService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 用户收藏记录Service业务层处理
 * 
 * @author singe
 * @date 2022-01-04
 */
@Service
public class UserCollectionRecordServiceImpl implements UserCollectionRecordService
{
    @Autowired
    private UserCollectionRecordMapper userCollectionRecordMapper;

    /**
     * 查询用户收藏记录
     * 
     * @param id 用户收藏记录主键
     * @return 用户收藏记录
     */
    @Override
    public UserCollectionRecord selectUserCollectionRecordById(Long id)
    {
        return userCollectionRecordMapper.selectUserCollectionRecordById(id);
    }

    /**
     * 查询用户收藏记录列表
     * 
     * @param userCollectionRecord 用户收藏记录
     * @return 用户收藏记录
     */
    @Override
    public List<UserCollectionRecord> selectPageList(UserCollectionRecord userCollectionRecord)
    {
        return userCollectionRecordMapper.selectUserCollectionRecordList(userCollectionRecord);
    }

    /**
     * 查询用户收藏记录列表
     *
     * @param userCollectionRecord 用户收藏记录
     * @return 用户收藏记录
     */
    @Override
    public List<UserCollectionRecord> selectUserCollectionRecordList(UserCollectionRecord userCollectionRecord)
    {
        return userCollectionRecordMapper.selectUserCollectionRecordList(userCollectionRecord);
    }

    /**
     * 新增用户收藏记录
     * 
     * @param userCollectionRecord 用户收藏记录
     * @return 结果
     */
    @Override
    public int insert(UserCollectionRecord userCollectionRecord)
    {
        userCollectionRecord.setCreateTime(DateUtils.getNowDate());
        return userCollectionRecordMapper.insert(userCollectionRecord);
    }

    /**
     * 修改用户收藏记录
     * 
     * @param userCollectionRecord 用户收藏记录
     * @return 结果
     */
    @Override
    public int update(UserCollectionRecord userCollectionRecord)
    {
        userCollectionRecord.setUpdateTime(DateUtils.getNowDate());
        return userCollectionRecordMapper.update(userCollectionRecord);
    }


    /**
     * 删除用户收藏记录信息
     * 
     * @param id 用户收藏记录主键
     * @return 结果
     */
    @Override
    public int deleteById(Long id)
    {
        return userCollectionRecordMapper.deleteById(id);
    }
    /**
     * 修改用户收藏记录
     *
     * @param userCollectionRecord 用户收藏记录信息
     * @return 结果
     */
    @Override
    @Transactional
    public int saveOrUpdate(UserCollectionRecord userCollectionRecord)
    {
        if(userCollectionRecord.getId() != null){
            userCollectionRecord.setUpdateTime(new Date());
            return userCollectionRecordMapper.update(userCollectionRecord);
        }else{
            userCollectionRecord.setCreateTime(new Date());
            return userCollectionRecordMapper.insert(userCollectionRecord);
        }
    }
}
